package com.neuedu.service.impl;

import com.neuedu.dao.UserDao;
import com.neuedu.dao.WorkDocInfoDao;
import com.neuedu.dao.WorkRuleDao;
import com.neuedu.factory.ClassFactory;
import com.neuedu.service.WorkRuleService;

import java.sql.Connection;
import java.sql.SQLException;
import java.text.ParseException;
import java.util.List;
import java.util.Map;

public class WorkRuleServiceImpl implements WorkRuleService {
    @Override
    public int addWorkRule(Object[] objs, Connection con) throws SQLException {
        WorkRuleDao add = (WorkRuleDao) ClassFactory.createObj("WorkRuleDao");
        try {
            return add.addWorkRule(objs, con);
        } catch (SQLException throwables) {
            con.rollback();
            throwables.printStackTrace();
            throw new RuntimeException("addWorkRule");
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return 0;
    }

    @Override
    public List<Map<String, Object>> queryWorkRule() {
        WorkRuleDao wrd = (WorkRuleDao) ClassFactory.createObj("WorkRuleDao");
        String sql = "SELECT rulename,deptname,`name` FROM workrule,deptment,`user` WHERE workrule.deptid=deptment.id AND `user`.deptid=deptment.id    AND `user`.isscheduling='是'";
        return wrd.queryWorkRule(sql);
    }

    @Override
    public int addWrokDocInfo(List<Map<String, Object>> list, Connection con) throws SQLException {
        WorkDocInfoDao wdid = (WorkDocInfoDao) ClassFactory.createObj("WorkDocInfoDao");
        try {
            return wdid.addWrokDocInfo(list, con);
        } catch (SQLException throwables) {
            throwables.printStackTrace();
            con.rollback();
            throw new RuntimeException("addWrokDocInfo");
        }
    }
}
